package com.xioyi.news.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.xioyi.news.domain.Article;
import com.xioyi.news.form.ArticleForm;
import com.xioyi.news.service.IArticleService;

public class ArticleAction extends DispatchAction {
	private IArticleService articleService;
	public ActionForward createArticleView(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		return mapping.findForward("ARTICLE.CREATE.VIEW");
	}
	public ActionForward createArticle(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		Article article=new Article();
		PropertyUtils.copyProperties(article, form);
		articleService.createArticle(article);
		ArticleForm f=(ArticleForm)form;
		System.out.println(f.getArticleContent());
		response.getWriter().print(article.getArticleId());
		return null;
	}
	
	public IArticleService getArticleService() {
		return articleService;
	}
	public void setArticleService(IArticleService articleService) {
		this.articleService = articleService;
	}
	
}
